﻿var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var compress = require('compression');
var cookieParser = require("cookie-parser");
var admin = require('./routes/admin.js.js');
const log = require('./logger.js');
var logger = require('./logger.js').logger;
const cors = require('cors');
require('./shzt.js');

log.use(app);
//手动记录，可以代替console.log
logger.info('test info 1');

//删除部分无用代码 
app.use(function (err, _req, res, _next) {
  //当token验证失败时会抛出如下错误

  if (err.name === 'UnauthorizedError') {
    //这个需要根据自己的业务逻辑来处理（ 具体的err值 请看下面）
    res.status(401).send('invalid token...');
  }
});

// 允许多个特定域名和端口跨域请求
app.use(cors({
  origin: "*"
}));
app.use(compress());
app.use(bodyParser.json({ limit: '50mb' })); // for parsing application/json
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
app.use(cookieParser());
//路由模块化
app.use('/admin', admin);

var server = app.listen(7777, async function () {
  logger.info("最大配置内存为" + require("v8").getHeapStatistics().total_available_size / 1024 / 1024)
})